package com.uj.speedcalculator;

public class Calculations {

	protected static double getNikeStyleSpeed(double speed) {
		return 60 / speed;
	}

	protected static double getOppositeSpeed(double speed, int currentMode) {
		switch (currentMode) {
		case metersMode:
			return speed * oneKmEqMile;
		case milesMode:
			return speed / oneKmEqMile;
		default:
			return 0;
		}
	}

	/**
	 * Returns given time for given level in hours
	 * 
	 * @param time for give level
	 * @param level- hrs,seconds or minutes
	 * @return
	 */
	protected static double getTimeInHrs(double time, int level) {
		switch (level) {
		case utMinutes:
			return time / 60;
		case utSecods:
			return time / 3600;
		case utHours:
		default:
			return time;
		}
	}

	/**
	 * Returns time for requested level 
	 * @param time in hours
	 * @param level - hrs,seconds or minutes
	 * @return
	 */
	protected static double getTimeForLevel(double time, int level) {
		switch (level) {
		case utMinutes:
			return time * 60;
		case utSecods:
			return time * 3600;
		case utHours:
		default:
			return time;
		}
	}
	
	/**
	 * @param speed
	 * @param distance - in units same as speed
	 * @param timeLevel - requested time level
	 * @return
	 */
	protected static double getTimeForDistance(double speed, double distance, int timeLevel)
	{
		double toptime = distance/speed;
		return getTimeForLevel(toptime,timeLevel);
	}
	
	/**
	 * @param speed
	 * @param time - in units same as speed
	 * @param distanceLevel - requested disntacne level
	 * @return
	 */
	protected static double getDistanceForTime(double speed, double time, int distanceLevel,int mode)
	{
		double topdistance =speed * time;
		return getDistanceInLevel(topdistance,distanceLevel,mode);
	}
	
	protected static double getTimeHr(double speed, double distance, int level,
			int mode) {
		return getDistance(distance, level, mode) / speed;
	}

	/**
	 * Returns distance in requested level
	 * @param distance 
	 * @param level for given level (meters or km or miles and feets)
	 * @param mode- meters or miles
	 * @return
	 */
	protected static double getDistanceInLevel(double distance, int level, int mode) {
		double r = 0;
		switch (level) {
		case udMain:
			r = distance;
			break;
		case udSmaller:
			switch (mode) {
			case milesMode:
				r = distance * oneMileFeets;
				break;
			case metersMode:
				r = distance * 1000;
				break;
			}
		}
		return r;
	}
	/**
	 * Returns distance in top level
	 * @param distance 
	 * @param level for given level (meters or km or miles and feets)
	 * @param mode- meters or miles
	 * @return
	 */
	protected static double getDistance(double distance, int level, int mode) {
		double r = 0;
		switch (level) {
		case udMain:
			r = distance;
			break;
		case udSmaller:
			switch (mode) {
			case milesMode:
				r = distance / oneMileFeets;
				break;
			case metersMode:
				r = distance / 1000;
				break;
			}
		}
		return r;
	}

	public final static double oneKmEqMile = 0.621371, oneMileFeets = 5280;
	public final static int milesMode = 2, metersMode = 1, utMinutes = 0,
			utHours = 1, utSecods = 2, udMain = 0, udSmaller = 1;

}
